<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="模板代码" prop="code">
        <el-input v-model="queryParams.code" placeholder="请输入模板代码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="模板名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入模板名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否启用" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择是否启用" clearable>
          <el-option v-for="dict in dict.type.CommDataStatus" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['shipment:template:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['shipment:template:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['shipment:template:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['shipment:template:export']">导出</el-button>
      </el-col>
      <el-col :span="2.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleTransform"
                   v-hasPermi="['shipment:template:export']">转为运单</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="templateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed/>
      <el-table-column label="组织" align="center" prop="dtMap.jcOrganizationIdDtLabel" fixed/>
      <el-table-column label="模板名称" align="center" prop="name" width="120" fixed/>
      <el-table-column label="模板代码" align="center" prop="code" width="120"/>
      <el-table-column label="承运商类型" align="center" prop="carrierType"  width="90">
        <template #default="scope">
          <dict-tag :options="dict.type.CarrierType" :value="scope.row.carrierType" />
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="feeType">
        <template #default="scope">
          <dict-tag :options="dict.type.Clearing" :value="scope.row.feeType" />
        </template>
      </el-table-column>
      <el-table-column label="车牌号" align="center" prop="license"  width="90" />
      <el-table-column label="运作模式" align="center" prop="operationPattern">
        <template #default="scope">
          <dict-tag :options="dict.type.OperationPattern" :value="scope.row.operationPattern" />
        </template>
      </el-table-column>
      <el-table-column label="司机名称" align="center" prop="outDriver" />
      <el-table-column label="运输方式" align="center" prop="shipmentMethod">
        <template #default="scope">
          <dict-tag :options="dict.type.TransportMenth" :value="scope.row.shipmentMethod" />
        </template>
      </el-table-column>
      <el-table-column label="运输协议号" align="center" prop="tan" width="100"/>
      <el-table-column label="承运商" align="center" prop="dtMap.jcCarrierIdDtLabel"  width="100" />
      <el-table-column label="车型" align="center" prop="dtMap.jcVehicleIdDtLabel" />
      <el-table-column label="司机电话" align="center" prop="outPhone"  width="110"/>
      <el-table-column label="起运站" align="center" prop="dtMap.jcFromOrganizationIdDtLabel" />
      <el-table-column label="目的站" align="center" prop="dtMap.jcToOrganizationIdLabel" />
      <el-table-column label="是否启用" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="dict.type.CommDataStatus" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createName" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="100"/>
      <el-table-column label="备注" align="center" prop="description" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template #default="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['shipment:template:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['shipment:template:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改运单模板对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="模板代码" prop="code">
              <el-input v-model="form.code" placeholder="请输入模板代码" :readonly="form.code" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="模板名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入模板名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运输协议号" prop="tan">
              <el-input v-model="form.tan" placeholder="请输入运输协议号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运作模式" prop="operationPattern">
              <el-select clearable v-model="form.operationPattern" placeholder="请选择运作模式">
                <el-option v-for="dict in dict.type.OperationPattern" :key="dict.value" :label="dict.label"
                           :value="parseInt(dict.value)"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="承运商" prop="jcCarrierId">
              <el-select clearable v-model="form.jcCarrierId" placeholder="请选择承运商">
                <el-option v-for="carrier in carrierList" :key="carrier.id" :label="carrier.name"
                           :value="carrier.id"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="承运商类型" prop="carrierType">
              <el-select clearable v-model="form.carrierType" placeholder="请选择承运商类型">
                <el-option v-for="dict in dict.type.CarrierType" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="付款方式" prop="feeType">
              <el-select clearable v-model="form.feeType" placeholder="请选择付款方式">
                <el-option v-for="dict in dict.type.Clearing" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车牌号" prop="license">
              <el-autocomplete v-model="form.license" :fetch-suggestions="queryLicenseSearch"
                               placeholder="请输入车牌号进行搜索" @select="handleLicenseSelect" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="司机名称" prop="outDriver">
              <el-autocomplete v-model="form.outDriver" :fetch-suggestions="queryDriverSearch"
                               placeholder="请输入司机名称进行搜索" @select="handleDriverSelect" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="司机电话" prop="outPhone">
              <el-input v-model="form.outPhone" placeholder="请输入司机电话" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="运输方式" prop="shipmentMethod">
              <el-select clearable v-model="form.shipmentMethod" placeholder="请选择运输方式">
                <el-option v-for="dict in dict.type.TransportMenth" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="车型" prop="jcVehicleId">
              <el-select clearable v-model="form.jcVehicleId" placeholder="请选择车型">
                <el-option v-for="vehicle in vehicleTypes" :key="vehicle.id" :label="vehicle.code" :value="vehicle.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="起运站" prop="jcFromOrganizationId">
              <el-select clearable filterable v-model="form.jcFromOrganizationId" placeholder="请选择起运站" @change="changeOrg">
                <el-option v-for="dict in orgList" :key="dict.id" :label="dict.name" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="目的站" prop="jcToOrganizationId">
              <el-select clearable filterable v-model="form.jcToOrganizationId" placeholder="请选择目的站" @change="changeOrg">
                <el-option v-for="dict in orgList" :key="dict.id" :label="dict.name" :value="dict.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="经由站" prop="orgIdsArray">
              <el-select clearable filterable v-model="form.orgIdsArray" placeholder="请选择经由站" style="width: 100%;" multiple @change="$forceUpdate()">
                <el-option v-for="dict in viaOrgIds" :key="dict.id" :label="dict.name" :value="dict.id + ''"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="是否启用" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in dict.type.CommDataStatus" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注" prop="description">
              <el-input v-model="form.description" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">台帐明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddJcLedgerDetail">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteJcLedgerDetail">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="jcLedgerDetailList" :row-class-name="rowJcLedgerDetailIndex"
          @selection-change="handleJcLedgerDetailSelectionChange" ref="jcLedgerDetail">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50" />
          <el-table-column label="承运商" prop="jcCarrierId" width="150">
            <template #default="scope">
              <el-select v-model="scope.row.jcCarrierId" placeholder="请选择承运商">
                <el-option v-for="carrier in carrierList" :key="carrier.id" :label="carrier.name"
                           :value="carrier.id"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="费用类型" prop="name">
            <template #default="scope">
              <el-select v-model="scope.row.jcFeeTypeId" placeholder="请选择费用类型" size="mini">
                <el-option v-for="dict in feeTypeData" :key="dict.id" :label="dict.name" :value="dict.id" @change="changeFeeType(scope.row,dict)" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="金额" prop="amount">
            <template #default="scope">
              <el-input type="number" v-model="scope.row.amount" placeholder="请输入金额" @input="changeAmount(scope.row)"/>
            </template>
          </el-table-column>
          <el-table-column label="税率" prop="taxrate">
            <template #default="scope">
              <el-select v-model="scope.row.taxrate" placeholder="请选择税率">
                <el-option v-for="dict in dict.type.TaxRate" :key="dict.value" :label="dict.label" :value="Number(dict.label)" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="税金" prop="input">
            <template #default="scope">
              <el-input type="number" v-model="scope.row.input" placeholder="请输入税金" />
            </template>
          </el-table-column>
          <el-table-column label="成本" prop="outcome">
            <template #default="scope">
              <el-input type="number" v-model="scope.row.outcome" placeholder="请输入成本" />
            </template>
          </el-table-column>
          <el-table-column label="收款方式" prop="collectMethod">
            <template #default="scope">
              <el-select v-model="scope.row.collectMethod" placeholder="请选择收款方式">
                <el-option v-for="dict in dict.type.CollectMethod" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="结算方式" prop="settlementMethod">
            <template #default="scope">
              <el-select v-model="scope.row.settlementMethod" placeholder="请选择结算方式">
                <el-option v-for="dict in dict.type.Clearing" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="description">
            <template #default="scope">
              <el-input v-model="scope.row.description" placeholder="请输入备注" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTemplate, getTemplate, delTemplate, addTemplate, updateTemplate } from "@/api/shipment/template";
import {allListCarrier} from "@/api/vehicle/carrier";
import {searchVehicleHead} from "@/api/vehicle/vehicleHead";
import {searchListDriver} from "@/api/vehicle/driver";
import {allListVehicle} from "@/api/vehicle/vehicle";
import {orgTree} from "@/api/kysys/sysOrganization";
import {listFeeTypeOption} from "@/api/fee/feeType";

export default {
  name: "ShipmentTemplate",
  dicts: ['CommDataStatus', 'CarrierType', 'OperationPattern', 'TransportMenth', 'Clearing', 'CollectMethod', 'TaxRate'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedJcLedgerDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 运单模板表格数据
      templateList: [],
      // 台帐明细表格数据
      jcLedgerDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        status: null,
        carrierType: null,
        feeType: null,
        license: null,
        operationPattern: null,
        outDriver: null,
        shipmentMethod: null,
        tan: null,
        jcCarrierId: null,
        jcDriverId: null,
        jcOrganizationId: null,
        jcVehicleId: null,
        jcVehicleHeadId: null,
        orgIds: null,
        outPhone: null,
        jcFromOrganizationId: null,
        jcToOrganizationId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [
          { required: true, message: "模板代码不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "模板名称不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "是否启用不能为空", trigger: "change" }
        ],
        license: [
          { required: true, message: "车牌号不能为空", trigger: "blur" }
        ],
        operationPattern: [
          { required: true, message: "运作模式不能为空", trigger: "change" }
        ],
        outDriver: [
          { required: true, message: "司机名称不能为空", trigger: "blur" }
        ],
        shipmentMethod: [
          { required: true, message: "运输方式不能为空", trigger: "change" }
        ],
        jcDriverId: [
          { required: true, message: "司机不能为空", trigger: "blur" }
        ],
        jcVehicleId: [
          { required: true, message: "车型ID不能为空", trigger: "change" }
        ],
        jcVehicleHeadId: [
          { required: true, message: "车头ID不能为空", trigger: "change" }
        ],
        outPhone: [
          { required: true, message: "司机电话不能为空", trigger: "blur" }
        ],
        jcFromOrganizationId: [
          { required: true, message: "起运站ID不能为空", trigger: "change" }
        ],
        jcToOrganizationId: [
          { required: true, message: "目的站ID不能为空", trigger: "change" }
        ]
      },
      carrierList: [],
      licenseList: [],
      driverList: [],
      vehicleTypes: [],
      orgList: [],
      // 经由站组织机构集合
      viaOrgIds: [],
      feeTypeData: []
    };
  },
  created() {
    this.getAllCarrier();
    this.getAllVehicle();
    this.getOrgList();
    this.getFeeTypeData();
    this.getList();
  },
  methods: {
    getAllCarrier() {
      allListCarrier().then(response => {
        this.carrierList = response.data;
      });
    },
    getAllVehicle() {
      allListVehicle().then(response => {
        this.vehicleTypes = response.data;
      });
    },
    /** 查询运单模板列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      listTemplate(this.queryParams).then(response => {
        this.templateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        createName: null,
        createTime: null,
        description: null,
        modifyName: null,
        modifyTime: null,
        name: null,
        status: 1,
        carrierType: null,
        feeType: null,
        license: null,
        operationPattern: null,
        outDriver: null,
        shipmentMethod: null,
        tan: null,
        jcCarrierId: null,
        jcDriverId: null,
        jcOrganizationId: null,
        jcVehicleId: null,
        jcVehicleHeadId: null,
        orgIds: null,
        orgIdsArray: null,
        outPhone: null,
        jcFromOrganizationId: null,
        jcToOrganizationId: null
      };
      this.jcLedgerDetailList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加运单模板";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTemplate(id).then(response => {
        this.form = response.data;
        if (response.data.orgIds) {
          this.form.orgIdsArray = response.data.orgIds.split(',');
        }
        this.changeOrg();
        this.jcLedgerDetailList = response.data.jcLedgerDetailList;
        this.open = true;
        this.title = "修改运单模板";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.jcLedgerDetailList = this.jcLedgerDetailList;
          if (this.form.orgIdsArray) {
            this.form.orgIds = this.form.orgIdsArray.join(",");
          }
          if (this.form.id != null) {
            updateTemplate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTemplate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除运单模板编号为"' + ids + '"的数据项？').then(function () {
        return delTemplate(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 台帐明细序号 */
    rowJcLedgerDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 台帐明细添加按钮操作 */
    handleAddJcLedgerDetail() {
      let obj = {};
      obj.createName = "";
      obj.description = "";
      obj.field1 = "";
      obj.modifyName = "";
      obj.modifyTime = "";
      obj.name = "";
      obj.status = "";
      obj.amount = "";
      obj.explain1 = "";
      obj.explain2 = "";
      obj.explain3 = "";
      obj.input = "";
      obj.occurrenceTime = "";
      obj.taxrate = "0.09";
      obj.jcFeeTypeId = "";
      obj.jcLedgerId = "";
      obj.cost = "";
      obj.type = "";
      obj.jcOrderId = "";
      obj.jcPrescoId = "";
      obj.jcDispatchId = "";
      obj.jcFeeSeedId = "";
      obj.jcOtherfeeId = "";
      obj.arrivePay = "";
      obj.backPay = "";
      obj.hxmoney = "";
      obj.montyPay = "";
      obj.nowPay = "";
      obj.whmoney = "";
      obj.cashAdvances = "";
      obj.oilPrepaid = "";
      obj.yuE = "";
      obj.zFy = "";
      obj.zGxyf = "";
      obj.zQtfy = "";
      obj.zShf = "";
      obj.zThf = "";
      obj.yajin = "";
      obj.yfYouka = "";
      obj.income = "";
      obj.outcome = "";
      obj.jcShipmentTemplateId = "";
      obj.jcCarrierId = "";
      obj.affirmTime = "";
      obj.isConfirm = "";
      obj.collectMethod = "";
      obj.payMethod = "";
      obj.settlementMethod = "";
      this.jcLedgerDetailList.push(obj);
    },
    /** 台帐明细删除按钮操作 */
    handleDeleteJcLedgerDetail() {
      if (this.checkedJcLedgerDetail.length == 0) {
        this.$modal.msgError("请先选择要删除的台帐明细数据");
      } else {
        const jcLedgerDetailList = this.jcLedgerDetailList;
        const checkedJcLedgerDetail = this.checkedJcLedgerDetail;
        this.jcLedgerDetailList = jcLedgerDetailList.filter(function (item) {
          return checkedJcLedgerDetail.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleJcLedgerDetailSelectionChange(selection) {
      this.checkedJcLedgerDetail = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('shipment/template/export', {
        ...this.queryParams
      }, `template_${new Date().getTime()}.xlsx`)
    },
    handleTransform() {
      // 开发中
      alert('开发中')
    },
    /** 车牌号搜索 */
    queryLicenseSearch(query) {
      this.licenseList = [];
      if (query && query !== "" && query.length >= 2) {
        searchVehicleHead(query).then(response => {
          this.licenseList = response.rows;
          this.licenseList.forEach(item => {
            item.value = item.code;
          });
        });
      }
    },
    /** 车牌号选中 */
    handleLicenseSelect(item) {
      this.form.license = item.code;
      this.form.jcVehicleHeadId = item.id;
    },
    /** 司机名称搜索 */
    queryDriverSearch(query, cb) {
      this.driverList = [];
      if (query && query !== "" && query.length >= 2) {
        searchListDriver(query).then(response => {
          // 将name 换为 value
          if (response.rows) {
            response.rows.forEach(item => {
              item.value = item.name;
            });
            cb(response.rows);
            this.driverList = response.rows;
          }
        });
      }
    },
    /** 司机名称选中 */
    handleDriverSelect(item) {
      this.form.outDriver = item.name;
      this.form.jcDriverId = item.id;
      this.form.outPhone = item.phone;
    },
    getOrgList() {
      this.orgList = []
      orgTree().then(response => {
        if (response.data) {
          this.orgList = response.data
        }
      })
    },
    changeOrg(value) {
      this.viaOrgIds = []
      // 从 orgList 中删除 jcFromOrganizationId、jcToOrganizationId
      this.viaOrgIds = this.orgList.filter(item => item.id !== this.form.jcFromOrganizationId && item.id !== this.form.jcToOrganizationId)
    },
    getFeeTypeData() {
      this.feeTypeData = []
      listFeeTypeOption('2.1').then(response => {
        if (response.data) {
          this.feeTypeData = response.data
        }
      })
    },
    changeFeeType(row, item) {
      row.name = item.name
      row.jcFeeTypeCode = item.code
    },
    changeAmount(row) {
      row.input = row.amount * row.taxrate
      row.income = row.amount - row.input
    },
  }
};
</script>
